<template>
  <div class="bottom-bar">
    <div class="check-content">
      <check-button class="check-button"
                    :is-checked="isSelectAll"
                    @click.native="checkClick">
<!--  :is-checked="isSelectAll" 如果isSlectAll为真那么check: ischecked 中该元素为真，被选中   -->
      </check-button>
      <span >全选</span>
    </div>
    <div class="price">
      合计：{{totalprice}}
    </div>
    <div class="calculate" @click="calcClick">去计算:{{checkLength}}</div>
  </div>
</template>

<script>
  import CheckButton from "../../../components/content/checkButton/CheckButton";
  export default {
    name: "CartBottomBar",
    data(){
      return{

      }
    },
    components: {
      CheckButton
    },
    methods: {
      checkClick() {
        if(this.isSelectAll){
          this.$store.state.cartList.forEach(item => item.checked = false)
        }else {
          this.$store.state.cartList.forEach(item => item.checked =true)
        }
      },
      calcClick(){
        if(!this.isSelectAll){
          this.$toast.show('请选择购买的商品', 2000)
        }
      }
    },
    computed: {
      totalprice() {
        return '¥' + this.$store.state.cartList.filter(item => {
          return item.checked
        }).reduce((preValue, item) => {
          return preValue + item.price * item.count
        },0).toFixed(2)
      },
      checkLength(){
        return this.$store.state.cartList.filter(item => item.checked).length
      },
      isSelectAll() {
        // return !(this.$store.state.cartList.filter(item => !item.checked).length)
        if(this.$store.state.cartList.length === 0)
          return false
        return !this.$store.state.cartList.find(item => !item.checked)
      }
    }
  }
</script>

<style scoped>
.bottom-bar{
  height: 40px;
  background-color: #ffffff;
  position: relative;
  display: flex;
  line-height: 40px;
  /*bottom: 40px;*/
}
.check-content{
  display: flex;
  margin-left: 10px;
  height: 40px;
  width: 60px;
  align-items: center;
}
.price{
  margin-left: 30px;
  flex: 1;
}
  .check-button{
    width: 20px;
    height: 20px;
    line-height: 20px;
    margin-right: 5px;
  }
  .calculate{
    width: 90px;
    color: #fff;
    text-align: center;
    background-color: red;
  }
</style>
